package com.atguigu.tingshu.order.task;

import com.atguigu.tingshu.common.constant.RedisConstant;
import com.atguigu.tingshu.common.constant.SystemConstant;
import com.atguigu.tingshu.model.order.OrderInfo;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBlockingDeque;
import org.redisson.api.RDelayedQueue;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RedisDelayHandle {

    @Autowired
    RedissonClient redissonClient;
    @Autowired
    OrderInfoService orderInfoService;

    @Scheduled(cron = "* * * * * ?")
    public void orderCancelDelayQueueHandle(){
        RBlockingDeque<String> blockingDeque = redissonClient.getBlockingDeque(RedisConstant.QUEUE_ORDER_CANCEL);
        String orderNo = blockingDeque.poll();
        if (orderNo != null) {
            orderInfoService.cancelOrder(orderNo);
        }
        log.info("定时任务执行了。。。。。。。");
    }

}
